import request from "@/utils/request";

export default {
  // 获取角色列表
  getRoleList(pageNo, pageSize) {
    return request({
      url: "/role/getRoleList",
      method: "get",
      params: {
        pageNo: pageNo,
        pageSize: pageSize,
      },
    });
  },

  // 获取角色信息
  getById(id) {
    return request({
      url: `/role/${id}`,
      method: "get",
    });
  },

  // 删除
  deleteById(id) {
    return request({
      url: `/role/delete/${id}`,
      method: "delete",
    });
  },

  // 更新
  update(role, permissionList) {
    return request({
      url: `/role/update`,
      method: "post",
      data: {
        role: role,
        permissionList: permissionList,
      },
    });
  },

  // 添加
  add(role, permissionList) {
    return request({
      url: `/role/add`,
      method: "post",
      data: {
        role: role,
        permissionList: permissionList,
      },
    });
  },

  save(role, permissionList) {
    if (role.id == null && role.id == undefined) {
      return this.add(role, permissionList);
    } else {
      // 修改

      return this.update(role, permissionList);
    }
  },
  // 查询所有的权限名称
  getRoleListByUserSelect() {
    return request({
      url: `/role/userSelectList`,
      method: "get",
    });
  },
};
